// .txt

beginzonescript;

variables;

short crime_tolerance = 200;
short last_abil;
short i;
short door1 = 0;
short door2 = 0;
short door3 = 0;
short e1count = 0;
short e2count = 0;
short heal_count = 0;

body;

beginstate INIT_STATE;
	sf(32,10,1);
	if (gf(32,4) == 0)
		sf(32,3,0);
		
	set_obj_act_at_dist(2,1);
	set_obj_act_at_dist(3,1);
	set_obj_act_at_dist(4,1);
	
//	set_name(,"");

	add_range_to_group(11,15,1);
	set_aggression(1001,8);
	
	//if (get_sdf() > 0) {
		//make_zone_hostile();
		//}

	last_abil = get_current_tick();
	
	set_crime_tolerance(crime_tolerance);
	break;

beginstate EXIT_STATE;

break;

beginstate START_STATE;
	if ((gf(32,6) > 0) && (door1 == 0)) {
		door1 = 1;
		give_object_message(3,DOOR_OPEN_MESSAGE);
		}
	if ((gf(32,7) > 0) && (door2 == 0)) {
		door2 = 1;
		give_object_message(4,DOOR_OPEN_MESSAGE);
		}
	if ((gf(32,3) > 0) && (door3 == 0)) {
		door3 = 1;
		give_object_message(2,DOOR_OPEN_MESSAGE);
		}

	// make sure pc can get out
	if (gf(32,4) > 0)
		sf(32,10,1);

	// clear zone?
	//if ((zone_clear(ME) == FALSE) && (get_flag(,) > 0)) {
		//print_str_color("",2);
		//clear_zone(ME);	
		//}
		
	//if ((get_crime_level() >= crime_tolerance) && (get_sdf(,) == 0)) {
	//	make_zone_hostile();
	//	set_flag(,,1);
	//	}

	// if (gf(,) == 0) {
	//	if (get_ran(1,0,100) < 10)
	//		give_char_text_bubble(,"");
	//	}
	
	if ((gf(32,3) == 0) && (gf(32,4) == 0) && (party_dist_to_nav(0) <= 5) && (party_near_nav(0,15))) {
		sf(32,3,1);
		sf(32,10,0);
		begin_talk_mode(10);
		}
	
	if ((gf(32,6) == 0) && (e1count == 0) && (dist_to_zone_loc(8,22,10) <= 2) && (dist_to_zone_loc(9,24,8) <= 2) && (dist_to_zone_loc(10,26,10) <= 2) && (party_dist_to_nav(1) <= 5)) {
		e1count = 1;
		begin_talk_mode(30);
		}
	if ((gf(32,7) == 0) && (e2count == 0) && (dist_to_zone_loc(8,47,53) <= 2) && (dist_to_zone_loc(9,49,55) <= 2) && (dist_to_zone_loc(10,51,53) <= 2) && (party_dist_to_nav(2) <= 5)) {
		e2count = 1;
		begin_talk_mode(40);
		}
	if ((gf(32,3) < 2) && (dist_to_zone_loc(8,20,48) <= 2) && (dist_to_zone_loc(9,22,46) <= 2) && (dist_to_zone_loc(10,24,48) <= 2) && (party_dist_to_nav(3) <= 6)) {
		sf(32,3,2);
		set_attitude(8,10);
		set_attitude(9,10);
		set_attitude(10,10);
		begin_talk_mode(50);
		}
		
	if (((is_combat()) && (tick_difference(last_abil,get_current_tick()) > 0)) || ((is_group()) && (tick_difference(last_abil,get_current_tick()) > 3))) {
		last_abil = get_current_tick();
		if ((e1count > 0) && (e1count < 100)) {
			if ((e1count == 2) || (e1count == 8)) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				if (char_ok(18) == FALSE) {
					spawn_creature(10);
					set_name(18,"Corrupting Shade");
					set_level(18,16);
					set_new_abil(18,11);
				  	place_particle_num(18,3,0,8);
					}
				if (char_ok(19) == FALSE) {
					spawn_creature(11);
					set_name(19,"Corrupting Shade");
					set_level(19,16);
					set_new_abil(19,11);
				  	place_particle_num(19,3,0,8);
					}
				if (char_ok(20) == FALSE) {
					spawn_creature(12);
					set_name(20,"Corrupting Shade");
					set_level(20,16);
					set_new_abil(20,11);
				  	place_particle_num(20,3,0,8);
					}
				if (char_ok(21) == FALSE) {
					spawn_creature(13);
					set_name(21,"Corrupting Shade");
					set_level(21,16);
					set_new_abil(21,11);
				  	place_particle_num(21,3,0,8);
					}
				}
			if ((e1count == 4) || (e1count == 10)) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				if (char_ok(22) == FALSE) {
					spawn_creature(14);
					set_name(22,"Icetouch Shade");
					set_level(22,16);
					set_new_abil(22,15);
				  	place_particle_num(22,3,0,8);
					}
				if (char_ok(23) == FALSE) {
					spawn_creature(15);
					set_name(23,"Icetouch Shade");
					set_level(23,16);
					set_new_abil(23,15);
				  	place_particle_num(23,3,0,8);
					}
				if (char_ok(24) == FALSE) {
					spawn_creature(16);
					set_name(24,"Icetouch Shade");
					set_level(24,16);
					set_new_abil(24,15);
				  	place_particle_num(24,3,0,8);
					}
				if (char_ok(25) == FALSE) {
					spawn_creature(17);
					set_name(25,"Icetouch Shade");
					set_level(25,16);
					set_new_abil(25,15);
				  	place_particle_num(25,3,0,8);
					}
				}
			if (e1count == 6) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				spawn_creature(18);
				set_name(26,"Essence Spectre");
				set_boss_level(26,1);
				set_new_abil(26,1);
			  	place_particle_num(26,3,0,8);
				}
			if (e1count == 12) {
				print_str_color("Their work done, the shades move on.",2);
				e1count = 100;
				sf(32,6,1);
				}
			e1count = e1count + 1;
			}

		if ((e2count > 0) && (e2count < 100)) {
			if ((e2count == 2) || (e2count == 11)) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				if (char_ok(36) == FALSE) {
					spawn_creature(28);
					set_name(36,"Crumbling Thahd");
					set_level(36,18);
				  	place_particle_num(36,3,0,8);
					}
				if (char_ok(37) == FALSE) {
					spawn_creature(29);
					set_name(37,"Crumbling Thahd");
					set_level(37,18);
				  	place_particle_num(37,3,0,8);
					}
				if (char_ok(38) == FALSE) {
					spawn_creature(30);
					set_name(38,"Crumbling Thahd");
					set_level(38,18);
				  	place_particle_num(38,3,0,8);
					}
				if (char_ok(39) == FALSE) {
					spawn_creature(31);
					set_name(39,"Crumbling Thahd");
					set_level(39,18);
				  	place_particle_num(39,3,0,8);
					}
				}
			if ((e2count == 5) || (e2count == 14)) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				if (char_ok(40) == FALSE) {
					spawn_creature(32);
					set_name(40,"Oozing Artila");
					set_level(40,16);
					set_new_abil(40,8);
				  	place_particle_num(40,3,0,8);
					}
				if (char_ok(41) == FALSE) {
					spawn_creature(33);
					set_name(41,"Oozing Artila");
					set_level(41,16);
					set_new_abil(41,8);
				  	place_particle_num(41,3,0,8);
					}
				if (char_ok(42) == FALSE) {
					spawn_creature(34);
					set_name(42,"Oozing Artila");
					set_level(42,16);
					set_new_abil(42,8);
				  	place_particle_num(42,3,0,8);
					}
				if (char_ok(43) == FALSE) {
					spawn_creature(35);
					set_name(43,"Oozing Artila");
					set_level(43,16);
					set_new_abil(43,8);
				  	place_particle_num(43,3,0,8);
					}
				}
			if (e2count == 8) {
				play_sound(101);
				print_str_color("The rune lets out a flash of green light.",2);
				spawn_creature(36);
				set_name(44,"Essence Wight");
				set_boss_level(44,1);
				set_new_abil(44,1);
			  	place_particle_num(26,3,0,8);
				}
			if (e2count == 17) {
				print_str_color("Their work done, the shades move on.",2);
				e2count = 100;
				sf(32,7,1);
				}
			e2count = e2count + 1;
			}

		if (heal_count > 0) {
			heal_count = heal_count + 1;
			if (heal_count == 2)
				heal_count = 0;
			}
			else if ((heal_count == 0) && (gf(32,3) == 2) && (char_ok(8)) && (char_ok(9)) && (char_ok(10))) {
				i = get_health(8);
				if (get_health(9) > i)
					i = get_health(9);
				if (get_health(10) > i)
					i = get_health(10);
				if ((i > get_health(8)) && (get_health(8) < get_max_health(8)))  {
					print_str_color("One of the wounded shades draws strength from the others.",2);
					run_sparkles_on_char(8,6,8,1);
					heal_char(8,i - get_health(8));
					heal_count = 1;
					}
				if ((i > get_health(9)) && (get_health(9) < get_max_health(9)))  {
					print_str_color("One of the wounded shades draws strength from the others.",2);
					run_sparkles_on_char(9,6,8,1);
					heal_char(9,i - get_health(9));
					heal_count = 1;
					}
				if ((i > get_health(10)) && (get_health(10) < get_max_health(10)))  {
					print_str_color("One of the wounded shades draws strength from the others.",2);
					run_sparkles_on_char(10,6,8,1);
					heal_char(10,i - get_health(10));
					heal_count = 1;
					}
				
				if ((get_health(8) < get_max_health(8) / 2) && (get_health(9) < get_max_health(9) / 2) && (get_health(10) < get_max_health(10) / 2)) {
					set_char_unkillable(8,0);
					set_char_unkillable(9,0);
					set_char_unkillable(10,0);
					}
				}
		}

break;

//beginstate 10;
//break;

//	print_str("");
//	set_terrain_string_range(".",3);
//	set_terrain_string_range("The sign says - .",3);
